home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / mweb / MWEB Utils / ws295sdk.exe / Ws2sdkzp.exe / SAMPLES / LAYERED / DTHOOK.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-06  |  3.6 KB  |  178 lines

  1. /*++
  2.  
  3.      Copyright (c) 1996 Intel Corporation
  4.      Copyright (c) 1996 Microsoft Corporation
  5.      All Rights Reserved
  6.  
  7.      Permission is granted to use, copy and distribute this software and
  8.      its documentation for any purpose and without fee, provided, that
  9.      the above copyright notice and this statement appear in all copies.
  10.      Intel makes no representations about the suitability of this
  11.      software for any purpose.  This software is provided "AS IS."
  12.  
  13.      Intel specifically disclaims all warranties, express or implied,
  14.      and all liability, including consequential and other indirect
  15.      damages, for the use of this software, including liability for
  16.      infringement of any proprietary rights, and including the
  17.      warranties of merchantability and fitness for a particular purpose.
  18.      Intel does not assume any responsibility for any errors which may
  19.      appear in this software nor any responsibility to update it.
  20.  
  21.  
  22.   Module Name:
  23.  
  24.     dthook.cpp
  25.  
  26.   Abstract:
  27.  
  28.     This module contains the hooks that allow specially-compiled
  29.     versions of layered provier DLL call into the debug/trace DLL.
  30.  
  31. --*/
  32.  
  33. #include "precomp.h"
  34.  
  35. //
  36. // Static Globals
  37. //
  38.  
  39. // Function pointers to the Debug/Trace DLL entry points
  40. static LPFNWSANOTIFY PreApiNotifyFP = NULL;
  41. static LPFNWSANOTIFY PostApiNotifyFP = NULL;
  42.  
  43. // Handle to the Debug/Trace DLL module
  44. static HMODULE       DTDll = NULL;
  45.  
  46. // Static string to pass to Debug/Trace notification functions
  47. static char LibName[] = "lsp";
  48.  
  49. //
  50. // Functions
  51. //
  52.  
  53.  
  54. LPFNWSANOTIFY
  55. GetPreApiNotifyFP(void)
  56. /*++
  57.  
  58.   Function Description:
  59.  
  60.       Returns a pointer to the WSAPreApiNotify function exported by
  61.       the Debug/Trace DLL.  This variable is global to this file only,
  62.       and is initialized during DT_Initialize().
  63.  
  64.   Arguments:
  65.  
  66.       None.
  67.  
  68.   Return Value:
  69.  
  70.       Returns whatever is stored in PreApiNotifyFP.
  71.  
  72. --*/
  73. {
  74.     return(PreApiNotifyFP);
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81. LPFNWSANOTIFY
  82. GetPostApiNotifyFP(void)
  83. /*++
  84.  
  85.   Function Description:
  86.  
  87.       Returns a pointer to the WSAPreApiNotify function exported by
  88.       the Debug/Trace DLL.  This variable is global to this file only,
  89.       and is initialized during DT_Initialize().
  90.  
  91.   Arguments:
  92.  
  93.       None.
  94.  
  95.   Return Value:
  96.  
  97.       Returns whatever is stored in PreApiNotifyFP.
  98.  
  99. --*/
  100. {
  101.     return(PostApiNotifyFP);
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108. void
  109. DTHookInitialize(void)
  110. /*++
  111.  
  112.   Function Description:
  113.  
  114.       Intializes this hook module.  Loads the Debug/Trace DLL, if
  115.       possible, and sets the global function pointers to point to the
  116.       entry points exported by that DLL.  If the DLL can't be loaded,
  117.       the function just returns and the function pointers are left at
  118.       NULL.
  119.  
  120.       This function MUST be called before any of the hook functions
  121.       are called, or the hook functions will not work.
  122.  
  123.   Arguments:
  124.  
  125.       None.
  126.  
  127.   Return Value:
  128.  
  129.       None.
  130.  
  131. --*/
  132. {
  133.     DTDll = (HMODULE)LoadLibrary("mydt_dll");
  134.  
  135.     if (DTDll == NULL) {
  136.         return;
  137.     }
  138.  
  139.     PreApiNotifyFP = (LPFNWSANOTIFY)GetProcAddress(
  140.         DTDll,
  141.         "WSAPreApiNotify");
  142.  
  143.     PostApiNotifyFP = (LPFNWSANOTIFY)GetProcAddress(
  144.         DTDll,
  145.         "WSAPostApiNotify");
  146. }
  147.  
  148.  
  149.  
  150.  
  151.  
  152. void
  153. DTHookShutdown(void)
  154. /*++
  155.  
  156.   Function Description:
  157.  
  158.       Should be called to shutdown Debug/Tracing.  The function
  159.       pointers are set to NULL, and the DLL is unloaded from memory.
  160.  
  161.   Arguments:
  162.  
  163.       None.
  164.  
  165.   Return Value:
  166.  
  167.       None.
  168.  
  169. --*/
  170. {
  171.     if (DTDll != NULL) {
  172.         FreeLibrary(DTDll);
  173.     }
  174.  
  175.     PreApiNotifyFP = NULL;
  176.     PostApiNotifyFP = NULL;
  177. }
  178.